home *** CD-ROM | disk | FTP | other *** search
- /**
- ** File ......... MyHandler.h
- ** Published .... 2004-04-20
- **/
- /*
- Copyright (C) 2004 grymse@alhem.net
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
- #ifndef _MYHANDLER_H
- #define _MYHANDLER_H
-
- #include <map>
- #include <string>
- #include "MinderHandler.h"
- #include <libxml/tree.h>
- #include <vector>
- #include <stdint.h>
- #include <Utility.h>
- #include "Configuration.h"
- #include "key.h"
- #include "MyMinionSocket.h"
- #include "TrackerSock.h"
-
-
- class MyHandler : public MinderHandler
- {
- public:
- struct PEER {
- PEER(const std::string& id,const std::string& address,port_t p)
- :escaped_peer_id(id),ip(address),port(p)
- ,uploaded(0),downloaded(0),left(0)
- ,updated(true),completed(false),stopped(false)
- ,last_contact(time(NULL))
- {
- for (size_t i = 0; i < id.size(); i += 3)
- {
- int x;
- sscanf( (char *)id.substr(i + 1,2).c_str(),"%02X",&x);
- peer_id[i / 3] = x;
- }
- }
- void update(const std::string& u,const std::string& d,const std::string& l) {
- uploaded = Utility::atoi64(u);
- downloaded = Utility::atoi64(d);
- left = Utility::atoi64(l);
- updated = true;
- }
- void stop() {
- if (!stopped)
- updated = true;
- stopped = true;
- }
- void complete() {
- if (!completed)
- updated = true;
- completed = true;
- }
- std::string escaped_peer_id;
- unsigned char peer_id[20];
- std::string ip;
- port_t port;
- uint64_t uploaded;
- uint64_t downloaded;
- uint64_t left;
- bool updated;
- bool completed;
- bool stopped;
- time_t last_contact;
- };
- typedef std::vector<PEER *> peer_v;
- typedef std::map<std::string,peer_v> peer_m;
- public:
- MyHandler(const std::string& );
- ~MyHandler();
-
- std::string GetVersion() {
- // std::string str = _VERSION_; return str;
- return GetString("server/identity");
- }
- unsigned char *GetKey_m2minion() { return k1; }
-
- int GetInt(const std::string& );
- std::string GetString(const std::string& );
- bool GetBoolean(const std::string& );
-
- std::string escape(const std::string& );
-
- PEER *reg_peer(const std::string& hash,
- const std::string& peer_id,
- const std::string& ip,
- port_t port);
-
- void CreatePeers(TcpSocket *,const std::string& hash,size_t);
- void SendList();
- void CheckDropped();
- void SendInit(MyMinionSocket *);
- size_t MapSize();
- void HtmlReport(TrackerSock *);
-
- private:
- Configuration m_config;
- peer_m m_peers;
- };
-
-
- #endif // _MYHANDLER_H
-